/*
 *  WaveFunctionLogXSineX.cpp
 *  SoundController0002
 *
 *  Created by jiro on 10/11/20.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#include "WaveFunctionLogXSinX.h"

#include "Constants.h"
#include <cmath>

namespace sc {

	double WaveFunctionLogXSinX::operator() ( double x ) const
	{
		x = ModifyX( x );
		x = slopeOfX * x + interceptOfX;
		if ( x == 0 ) { 
			return 0.0;
		}
		return - normalizer * std::log( pow( x, powerOfXOfLog ) ) * std::sin( 2 * Pi * cycle * x );
	}

	bool WaveFunctionLogXSinX::operator == ( const WaveFunction& rhs ) const
	{
		if ( this->WaveFunction::operator == ( rhs ) ) {
			const WaveFunctionLogXSinX& ref  = dynamic_cast< const WaveFunctionLogXSinX& >( rhs );
			if ( powerOfXOfLog == ref.powerOfXOfLog ) 
			{
				return true;
			}
		}
		return false;
	}
	
	bool WaveFunctionLogXSinX::operator != ( const WaveFunction& rhs ) const
	{
		return not( *this == rhs );
	}
		
	bool WaveFunctionLogXSinX::operator < ( const WaveFunction& rhs ) const
	{
		if ( type != rhs.GetType() ) {
			return type < rhs.GetType();
		}
		if ( this->WaveFunction::operator < ( rhs ) ) {
			return true;
		}
		const WaveFunctionLogXSinX& ref = dynamic_cast< const WaveFunctionLogXSinX& >( rhs );
		if ( powerOfXOfLog != ref.powerOfXOfLog ) {
			return powerOfXOfLog < ref.powerOfXOfLog;
		}
		return false;
	}
	
	double WaveFunctionLogXSinX::GetPowerOfXOfLog() const
	{
		return powerOfXOfLog;
	}

	WaveFunctionLogXSinX::WaveFunctionLogXSinX( double powerOfXOfLog, double cycle, bool isReverse, bool isNormalize )
		: WaveFunction( Type_LogXSinX, 1 / cycle, Range( 0, cycle / 2.0 ), 1, isReverse ? -1 : 1, isReverse ? cycle / 2.0 : 0 ),
		  powerOfXOfLog( powerOfXOfLog )
	{
		if ( isNormalize ) {
			SetNormalizer();
		}
	}
}
